//
//  rechargeView.m
//  tcpoctest
//
//  Created by gump on 6/9/13.
//  Copyright (c) 2013 gump. All rights reserved.
//

#import "rechargeView.h"

@implementation rechargeView

-(void)initUI
{
    self.view.backgroundColor = VIEW_BG_COLOR;
    
    [self createTitle];
    self.mtitle.text = @"充值";
    
    UIBarButtonItem *backItem = [self createBarBackButtonItemWithTitle:@"返回" target:self action:@selector(backButtonPressed)];
    self.navItem.leftBarButtonItem = backItem;
    
    webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,
                                                          TOPBAR_HIGHT,
                                                          WINDOW_WIDTH,
                                                          WINDOW_HIGTH - TOPBAR_HIGHT)];
    
    webView.scalesPageToFit =YES;
    webView.delegate =self;
    
    [self.view addSubview:webView];
}

#pragma mark -private fun-
-(void)backButtonPressed
{
    [[ViewManager sharedViewManager] backView:self];
}

-(void)viewWillShow
{
    NSString *mail = [DataControl shareControl].personDS.uinfo.mail;
    if (mail != nil && ![mail isEqualToString:@""]) {
       NSString *strppnum = [NSString stringWithFormat:@"%d",
                             [DataControl shareControl].personDS.uinfo.ppNumber];
    
        NSString *strURL = [NSString stringWithFormat:
                            @"http://user.peng7.net/apliy/index.php?user=%@_%@_%@_"
                            ,strppnum
                            ,T_PROJECTNAME2
                            ,T_DEVICENAME];
        NSURL *url =[NSURL URLWithString:strURL];
        NSURLRequest *request =[NSURLRequest requestWithURL:url];
        [webView loadRequest:request];
    }
}

#pragma mark -web delegat-
- (void)webViewDidStartLoad:(UIWebView *)webView
{
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    UIAlertView *alterview = [[UIAlertView alloc] initWithTitle:@"网页打开有问题耶"
                                                        message:[error localizedDescription]
                                                       delegate:nil
                                              cancelButtonTitle:nil
                                              otherButtonTitles:@"OK", nil];
    [alterview show];
}

@end
